package com.reform.res;

import java.util.ArrayList;
import java.util.List;
/**
 * API 统一返回状态码
 */
public enum ResultCode {

    /* 成功状态码 */
    SUCCESS(200, "成功"),
    /* 失败状态码 */
    FAILURE(500, "失败"),

    /* 其他错误：2001-2999 */
    OTHER_ERROR(6003,"其他异常"),

    /* 参数错误：3001-3999 */
    PARAM_IS_MISSING(3001, "参数缺省"),
    PARAM_IS_WRONG(3002, "参数有误"),
    PARAM_EMAIL_IS_WRONG(3003, "邮箱号有误"),
    PARAM_EMAILCODE_IS_WRONG(3004, "邮箱验证码有误"),
    PARAM_NUM_IS_TOO_LONG(3005, "数字超过限制"),
    PARAM_TIME_IS_WRONG(3006, "时间格式错误"),
    PARAM_JSON_IS_WRONG(3007, "JSON字符串格式错误"),
    No_Such_Element_Exception(3008, "没有这样的元素"),
    //PARAM_TYPE_BIND_ERROR(10002, "参数类型错误"),
    //PARAM_NOT_COMPLETE(10004, "参数缺失"),
    //
    /* 用户错误：20001-29999*/
    //USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_NOT_WORKING(4002,"人事处无该教师信息"),
    USER_AUTH_FAIL(4003,"用户权限认证失败"),
    USER_ARGS_ERROR(4004, "工号或密码错误"),
    USER_NOT_REGISTRIED(4005, "该用户尚未注册"),
    USER_AUTH_Login_LAPSE(4006, "请重新登录"),
    USER_HAS_REGISTRIED(4007, "该用户已注册"),
    USER_HAS_ADMINED(4008, "该账号已是管理员"),
    USER_PASSWORD_ERROR(4009, "该用户密码有误"),
    USER_EMAIL_NOT_CHAHGED(4010, "邮箱未修改"),
    USER_NEWPASSWORD_EQUALS_OLDPASSWORD(4011, "新密码不可与原密码相同"),
    USER_HASNOT_LOGIN(4012, "用户尚未登录"),
    DEP_HAVE_ADMINED(4013, "该部门已有管理员"),
    //
    /* 业务错误：30001-39999 */
    //SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),
    //
    /* 系统错误：40001-49999 */
    //SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
    SYSTEM_REDIS_CONNECTION_ERROR(6001,"Redis超时，请重新发送"),
    SYSTEM_INITIALIZE_ERROR(6002,"用户初始化失败"),
    SYSTEM_ERROR(6003,"系统错误"),
    //
    ///* 数据错误：50001-599999 */
    //RESULE_DATA_NONE(50001, "数据未找到"),
    //DATA_IS_WRONG(50002, "数据有误"),
    //DATA_ALREADY_EXISTED(50003, "数据已存在"),
    //
    ///* 接口错误：60001-69999 */
    //INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
    //INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
    //INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
    //INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
    //INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
    //INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),
    //
    ///* 权限错误：70001-79999 */
    //PERMISSION_NO_ACCESS(70001, "无访问权限")
    ;

    private Integer code;

    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

    //校验重复的code值 (**可去除**)
    public static void main(String[] args) {
        ResultCode[] ApiResultCodes = ResultCode.values();
        List<Integer> codeList = new ArrayList<Integer>();
        for (ResultCode ApiResultCode : ApiResultCodes) {
            if (codeList.contains(ApiResultCode.code)) {
                System.out.println(ApiResultCode.code);
            } else {
                codeList.add(ApiResultCode.code());
            }
        }
    }
}
